package cn.java.lambda.test3;

import java.util.function.BiFunction;

/**
 * 测试BiFunction函数式接口
 *
 * @author 攀博课堂(www.pbteach.com)
 * @version 1.0
 **/
public class TestBiFunction {

    public static void main(String[] args) {
        //求两个数的和
        BiFunction<Integer, Integer, Integer> fun1 = (x, y) -> x + y;
        //求两个数的乘积
        BiFunction<Integer, Integer, Integer> fun2 = (x, y) -> x * y;
        //调用方法
        System.out.println(operate(fun1, 1, 2));
        System.out.println(operate(fun2, 1, 2));
        //简化
        System.out.println(operate((x, y) -> x * y, 1, 2));
    }

    //实现两个数运算
    public static int operate(BiFunction<Integer, Integer, Integer> fun, int n1, int n2) {
        return fun.apply(n1, n2);

    }
}
